package com.android.Servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.android.Bean.LoginCheckBean;

import net.sf.json.JSONObject;

@SuppressWarnings("serial")
public class LoginRegisterServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("gbk");
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		LoginCheckBean loginBean = new LoginCheckBean();
		try {
			boolean flag = loginBean.loginUser(username, password);
			Map<String, Boolean> map = new HashMap<String, Boolean>();
			map.put("flag", flag);
			JSONObject json = new JSONObject();
			json.putAll(map);
			PrintWriter pw = response.getWriter();
			pw.write(json.toString());
			pw.flush();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
